package dev.werillib.android

import android.content.Context
import dev.werillib.utils.d
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader


/**
 * create by weril 2018/12/17
 */
fun getJson(fileName: String, context: Context): String {
    //将json数据变成字符串
    val stringBuilder = StringBuilder()
    try {
        //获取assets资源管理器
        val assetManager = context.assets
        //通过管理器打开文件并读取
        val bf = BufferedReader(
            InputStreamReader(
                assetManager.open(fileName)
            )
        )
        var line: String
        while (true) {
            line = bf.readLine() ?: break
            stringBuilder.append(line)
        }
        bf.close()
    } catch (e: IOException) {
        e.printStackTrace()
    }
    d(stringBuilder.toString())
    return stringBuilder.toString()
}